<!--职业添加-->
<template>
  <div style="background:#ffffff;">
    <div>
      <el-row style="background:#ffffff;">
        <el-col :span="20">
          <el-button type="info" @click="$router.go(-1)" size="mini"  icon="el-icon-arrow-left">返回</el-button>
        </el-col>
      </el-row>
    </div>
    <el-row>
      <el-col :span="24">
        <el-form
          :model="PositionEdit"
          label-width="100px"
          label-position="top"
          :inline="true"
          ref="PositionEdit"
          size="medium"
          :rules="rules"
        >
          <el-form-item label="名称" prop="Title">
            <el-input v-model="PositionEdit.Title"></el-input>
          </el-form-item>
          <el-form-item label="层级" prop="LevelID">
            <el-input v-model.number="PositionEdit.LevelID"></el-input>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <div>
      <el-button type="primary" @click="GetPosition('PositionEdit')" icon="el-icon-check" size="mini">保存</el-button>&nbsp;
     
      <el-button type="info" @click="$router.go(-1)" size="mini" icon="el-icon-close">取消</el-button>
     
    </div>
  </div>
</template>
<style lang="scss" scoped>
.el-row {
  margin-bottom: 10px;
}
.el-form-item {
  width: 49%;
}
</style>
<script>
export default {
  data() {
    return {
      PositionEdit: {
        Title:"",
        LevelID:""
      },
      Type: "Add",
      rules:{
        Title:[
          {required:true,message:'请输入内容',trigger:'blur'}
        ],
        LevelID:[
          {required:true,message:'请输入内容',trigger:'blur'},
          { type: 'integer', message: '只能输入整数', trigger: 'blur' }
        ]
      }
    };
  },
  mounted() {
    if (Object.keys(this.$route.query).length) {
      //编辑
      this.Type = "Edit";
      this.$axios({
        url: "/HrApi/Position/GetPositionId",
        method: "GET",
        params: {
          id: this.$route.query["pk_Position"],
        },
      }).then((res) => {
        if (!res.data.code) {
          this.PositionEdit = res.data.data;
        } 
        else {
          this.$message.error(res.data.msg);
        }
      });
    }
  },
  methods: {
    //添加
    GetPosition(Edit) {
      this.$refs[Edit].validate((valid) => {
        if (!valid) {
          return false;
        }
        //执行请求
        this.$axios({
          url: "/HrApi/Position/UpdatePosition",
          method: "POST",
          data: this.$Qs.stringify({
            pk_User:this.$store.state.UserInfo.pk_User,
            Position: JSON.stringify(this.PositionEdit),
            Type: this.Type
          }),
        }).then((res) => {
          if (!res.data.code) {                      
              //添加成功，重置表单            
            this.$message.success(res.data.msg);
            this.$refs[Edit].resetFields();
          } else {
            this.$message.error(res.data.msg);
          }
        });
      });
    }
  },

};
</script>
